// manager/pages/performancedesc/index.js
import { getSystemInfo } from '../../../utils/getSystemInfo';
import { request } from '../../../utils/request';
import util from '../../../common/util';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: {},
        params: {
            busiType: "",
            busiCode: "",
            search: "",
            startDate: "",
            endDate: "",
        },
        list: {},
        show: false,
        actions: [],
        phone: "",
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            params: Object.assign(this.data.params,options)
        })
        this.getUserInfo();
        this.getMyBusiReportInfo()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },
    // 获取当前登录者的用户信息
    getUserInfo(e) {        
        request({
            url: "/user/getUserInfo",
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {}
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    userInfo: res.data.userInfo
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    /**
     * 获取填报记录详情
     */
    getMyBusiReportInfo() {
        request({
            url: `/busi/reportConfig/getMyBusiReportInfo`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: this.data.params
        }).then(res => {
            console.log(res)
            if(res.code == 0){
                let list = res.data || [];
                list.map(item => {
                    item.creationTime = item.creationTime&&util.formatTime(new Date(item.creationTime))
                    return item
                })
                this.setData({
                    list
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    /**
     * 输入框输入时
     */
    input(e){
        let key = e.target.dataset.key;
        this.setData({
            ['params.'+key]: e.detail.value,
            // isFilter: !!e.detail.value,
        })
    },
    // 搜索
    searchConfirm(e){
        console.log(e.detail.value)
        this.setData({
            'params.search': e.detail.value
        })
        this.getMyBusiReportInfo();
    },
    /**
     * 日期选择
     */
    bindDateChange: function(e) {
        let { key } = e.currentTarget.dataset;
        this.setData({
            ['params.'+key]: e.detail.value
        })
    },
    searchBtn(e){
        this.getMyBusiReportInfo();
    },
    /**
     * 拨打电话
     */
    makePhoneCall(e) {
        console.log(e)
        let { phone } = e.currentTarget.dataset;
        if(!phone){
            wx.showToast({
                title: "暂无联系方式",
                icon: 'none',
                duration: 2000
            })
            return
        }
        getSystemInfo({
            android: () => {
                let actions = [
                    { name: phone, color: '#999', disabled: true },
                    { name: '呼叫', color: '#000' },
                ]
                this.setData({
                    show: true,
                    phone: phone,
                    actions
                })
            },
            ios: () => {
                wx.makePhoneCall({
                    phoneNumber: phone
                })
            }
        })
    },
    onSelect(e) {
        console.log(e)
        this.setData({
            show: false
        })
        wx.makePhoneCall({
            phoneNumber: this.data.phone
        })
    },
    onCancel() {
        this.setData({ show: false });
    },
    /**
     * 跳转详情
     */
    detail(e){
        let { item } = e.currentTarget.dataset;
        console.log(item)
        if(item.busiType == 1){
            wx.navigateTo({
              url: `/manager/pages/personalreporting/index?name=${item.busiName}&id=${item.configId}&code=${item.busiCode}&busiType=${item.busiType}&detailId=${item.id}`,
            })
        }
        if(item.busiType == 2){
            wx.navigateTo({
              url: `/manager/pages/bindcardreporting/index?name=${item.busiName}&id=${item.configId}&code=${item.busiCode}&busiType=${item.busiType}&detailId=${item.id}`,
            })
        }
        if(item.busiType == 3){
            wx.navigateTo({
              url: `/manager/pages/corporatereporting/index?name=${item.busiName}&id=${item.configId}&code=${item.busiCode}&busiType=${item.busiType}&detailId=${item.id}`,
            })
        }
        if(item.busiType == 4){
            wx.navigateTo({
              url: `/manager/pages/otherreporting/index?name=${item.busiName}&id=${item.configId}&code=${item.busiCode}&busiType=${item.busiType}&detailId=${item.id}`,
            })
        }
    }
})